#include<func.h>
time_t start;
struct timeval t1;

void sigfunc(int signum)
{
    struct timeval t2;
    gettimeofday(&t2,NULL);
    printf("当前执行时间是%ld秒\n",t2.tv_sec-t1.tv_sec);
}
int main()
{
    signal(SIGALRM,sigfunc);
    struct itimerval t;
    bzero(&t,sizeof(t));
    t.it_value.tv_sec=3;
    t.it_interval.tv_sec=2;
    start=time(NULL);
    printf("当前时间是%s",ctime(&start));
    int ret=gettimeofday(&t1,NULL);
    ERROR_CHECK(ret,-1,"gettimeofday")
    ret=setitimer(ITIMER_REAL,&t,NULL);
    ERROR_CHECK(ret,-1,"setitimer")
    char buf[128]={0};
    read(STDIN_FILENO,buf,sizeof(buf));
    printf("buf=%s\n",buf);
    return 0;
    
}